import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
import * as serviceWorker from './serviceWorker'

// 导入redux
import { createStore, applyMiddleware } from 'redux'
// 导入支持异步的redux中间件
import thunk from 'redux-thunk'
// 导入react-redux
import { Provider } from 'react-redux'

// 导入reducer
import reducers from './reducers'
// 导入action
import { add, sub } from './actions/countAction'
import { getSwiper } from './actions/swiperAction'

// 创建 store
const store = createStore(reducers, applyMiddleware(thunk))

console.log(store.getState())

// 通过 dispatch 触发 对应的 reducer
store.dispatch(add())

console.log(store.getState())

// 通过 dispatch 触发 对应的 reducer
store.dispatch(sub(10))

console.log(store.getState())

// 通过 dispatch 触发 对应的 reducer，获取轮播图数据
store.dispatch(getSwiper).then(function() {
  console.log(store.getState())
})

ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('root')
)

serviceWorker.unregister()
